#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
map<string,int> se;
string opt,ad;
int n;
bool uncode(string code,ll &a,ll &b,ll &c,ll &d,ll &e)
{
	bool flag=0;
	int i;
	bool fist;
	fist=0;
	a=0;
	for(i=0;i<code.size();i++)
		if(code[i]>='0'&&code[i]<='9')
		{
			flag=1;
			if(a==0&&code[i]=='0')fist=1;
			a=a*10+code[i]-'0';
			if(a>255)return 0;
		}
		else break;
	if(!flag)return 0;
	flag=0;
	if(fist&&a!=0)return 0;
	if(code[i]!='.')return 0;
	fist=0;
	b=0;
	for(i+=1;i<code.size();i++)
		if(code[i]>='0'&&code[i]<='9')
		{
			flag=1;
			if(b==0&&code[i]=='0')fist=1;
			b=b*10+code[i]-'0';
			if(b>255)return 0;
		}
		else break;
	if(!flag)return 0;
	if(fist&&b!=0)return 0;
	if(code[i]!='.')return 0;
	fist=0;
	flag=0;
	c=0;
	for(i+=1;i<code.size();i++)
		if(code[i]>='0'&&code[i]<='9')
		{
			flag=1;
			if(c==0&&code[i]=='0')fist=1;
			c=c*10+code[i]-'0';
			if(c>255)return 0;
		}
		else break;
	if(!flag)return 0;
	if(fist&&c!=0)return 0;
	if(code[i]!='.')return 0;
	d=0;
	flag=0;
	fist=0;
	for(i+=1;i<code.size();i++)
		if(code[i]>='0'&&code[i]<='9')
		{
			flag=1;
				if(d==0&&code[i]=='0')fist=1;
			d=d*10+code[i]-'0';
			if(d>255)return 0;
		}
		else break;
		if(!flag)return 0;
		if(fist&&d!=0)return 0;
	if(code[i]!=':')return 0;
	e=0;
	fist=0;
	for(i+=1;i<code.size();i++)
		if(code[i]>='0'&&code[i]<='9')
		{
			if(e==0&&code[i]=='0')fist=1;
			flag=1;
			e=e*10+code[i]-'0';
			if(e>65535)return 0;
		}
		else return 0;
	if(fist&&e!=0)return 0;
	for(i+=1;i<code.size();i++)
		return 0;
	return flag;
}
int main()
{
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		cin>>opt>>ad;
		ll a,b,c,d,e;
		if(opt[0]=='S')
		{
			if(!uncode(ad,a,b,c,d,e))
			{
				printf("ERR\n");
				continue;
				}
			else
			{
				if(se[ad]){printf("FAIL\n");continue;}
				else {printf("OK\n");se[ad]=i;continue;}
			}
		}
		if(opt[0]=='C')
		{
			if(!uncode(ad,a,b,c,d,e)){printf("ERR\n");continue;}
			else 
			{
				if(se[ad]){printf("%d\n",se[ad]);continue;}
				else {printf("FAIL\n");continue;}
			}
		}
	}
	return 0;
}
